package com.ruoyi.web.controller.shopping;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.shopping.CartItems;
import com.ruoyi.system.service.shopping.ICartItemsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * cartController
 * 
 * @author zjh
 * @date 2025-11-21
 */
@RestController
@RequestMapping("/cart/cart")
public class CartItemsController extends BaseController
{
    @Autowired
    private ICartItemsService cartItemsService;

    /**
     * 查询cart列表
     */
//    @PreAuthorize("@ss.hasPermi('cart:cart:list')")
    @GetMapping("/list")
    public TableDataInfo list(CartItems cartItems)
    {
        startPage();
        List<CartItems> list = cartItemsService.selectCartItemsList(cartItems);
        return getDataTable(list);
    }

    /**
     * 导出cart列表
     */
//    @PreAuthorize("@ss.hasPermi('cart:cart:export')")
    @Log(title = "cart", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CartItems cartItems)
    {
        List<CartItems> list = cartItemsService.selectCartItemsList(cartItems);
        ExcelUtil<CartItems> util = new ExcelUtil<CartItems>(CartItems.class);
        util.exportExcel(response, list, "cart数据");
    }

    /**
     * 获取cart详细信息
     */
//    @PreAuthorize("@ss.hasPermi('cart:cart:query')")
    @GetMapping(value = "/{cartItemId}")
    public AjaxResult getInfo(@PathVariable("cartItemId") Long cartItemId)
    {
        return success(cartItemsService.selectCartItemsByCartItemId(cartItemId));
    }

    /**
     * 新增cart
     */
//    @PreAuthorize("@ss.hasPermi('cart:cart:add')")
    @Log(title = "cart", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CartItems cartItems)
    {
        return toAjax(cartItemsService.insertCartItems(cartItems));
    }

    /**
     * 修改cart
     */
//    @PreAuthorize("@ss.hasPermi('cart:cart:edit')")
    @Log(title = "cart", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CartItems cartItems)
    {
        return toAjax(cartItemsService.updateCartItems(cartItems));
    }

    /**
     * 删除cart
     */
//    @PreAuthorize("@ss.hasPermi('cart:cart:remove')")
    @Log(title = "cart", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cartItemIds}")
    public AjaxResult remove(@PathVariable Long[] cartItemIds)
    {
        return toAjax(cartItemsService.deleteCartItemsByCartItemIds(cartItemIds));
    }
}
